{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# EARLY (FREQUENT) RIDERS ONLY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Loading required package: data.table\n",
      "\n",
      "Loading required package: feather\n",
      "\n",
      "Loading required package: ggplot2\n",
      "\n",
      "Loading required package: clusterSEs\n",
      "\n",
      "Loading required package: AER\n",
      "\n",
      "Loading required package: car\n",
      "\n",
      "Loading required package: carData\n",
      "\n",
      "Loading required package: lmtest\n",
      "\n",
      "Loading required package: zoo\n",
      "\n",
      "\n",
      "Attaching package: 'zoo'\n",
      "\n",
      "\n",
      "The following objects are masked from 'package:base':\n",
      "\n",
      "    as.Date, as.Date.numeric\n",
      "\n",
      "\n",
      "Loading required package: sandwich\n",
      "\n",
      "Loading required package: survival\n",
      "\n",
      "Loading required package: Formula\n",
      "\n",
      "Loading required package: plm\n",
      "\n",
      "\n",
      "Attaching package: 'plm'\n",
      "\n",
      "\n",
      "The following object is masked from 'package:data.table':\n",
      "\n",
      "    between\n",
      "\n",
      "\n",
      "\n",
      " When using this package, cite: \n",
      " \n",
      " Justin Esarey and Andrew Menger (2019). \n",
      " \"Practical and Effective Approaches to Dealing with Clustered Data.\" \n",
      " Political Science Research and Methods 7(3): 541-549. \n",
      " URL: https://doi.org/10.1017/psrm.2017.42. \n",
      "\n",
      "\n",
      "Loading required package: formula.tools\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import_and_maybe_install <- function(pkgs){\n",
    "    missing_packages <- character(0)\n",
    "    for(pkg in pkgs){\n",
    "        tryCatch({\n",
    "            require(pkg, character.only=TRUE )\n",
    "        },warning=function(err){\n",
    "            missing_packages <<- c(missing_packages,pkg)\n",
    "        })\n",
    "    }\n",
    "    if(length(missing_packages)){\n",
    "            install.packages(missing_packages)\n",
    "            sapply(missing_packages, require, character.only=TRUE)\n",
    "    }\n",
    "    invisible(NULL)\n",
    "}\n",
    "import_and_maybe_install(c(\"data.table\", \"feather\", \"ggplot2\",\"clusterSEs\",\"formula.tools\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_DIR <- \"~/connector/20200226/analytic_datasets\"\n",
    "\n",
    "commute_ride_data <- read_feather( file.path(DATA_DIR,\"commute_ride_data.feather\"))\n",
    "setDT(commute_ride_data)\n",
    "\n",
    "# FACTOR VARIABLES\n",
    "stopifnot(commute_ride_data[,class(fAid) == \"factor\"]) # rider id\n",
    "stopifnot(commute_ride_data[,class(fDate) == \"factor\"]) # date id\n",
    "\n",
    "route_field <- sprintf(\"route_%s_10_ride\",1:21)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FILTER on EARLY RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Early Riders"
     ]
    },
    {
     "data": {
      "text/html": [
       "3908"
      ],
      "text/latex": [
       "3908"
      ],
      "text/markdown": [
       "3908"
      ],
      "text/plain": [
       "[1] 3908"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Data"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3354470</td><td>805199 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 3354470 & 805199 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 3354470 | 805199  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 3354470 805199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Early riders only"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1792156</td><td>640522 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 1792156 & 640522 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 1792156 | 640522  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 1792156 640522"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dates = commute_ride_data[,.N,keyby=.(date,fDate)]\n",
    "MAX_DATE = dates[15,date]\n",
    "\n",
    "early_riders = commute_ride_data[date <= MAX_DATE & did_ride,1,keyby=aid][,V1:=NULL]\n",
    "cat(\"Number of Early Riders\")\n",
    "early_riders[,.N]\n",
    "\n",
    "setkey(commute_ride_data,aid)\n",
    "crd = commute_ride_data[early_riders]\n",
    "\n",
    "cat(\"Full Data\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "cat(\"Early riders only\")\n",
    "crd[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "#commute_ride_data[,1,aid][,.N]\n",
    "#commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV),.N]\n",
    "#commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV),1,aid][,.N]\n",
    "\n",
    "commute_ride_data = crd\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "0.796019900497512"
      ],
      "text/latex": [
       "0.796019900497512"
      ],
      "text/markdown": [
       "0.796019900497512"
      ],
      "text/plain": [
       "[1] 0.7960199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "1792156"
      ],
      "text/latex": [
       "1792156"
      ],
      "text/markdown": [
       "1792156"
      ],
      "text/plain": [
       "[1] 1792156"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "64/80.4\n",
    "commute_ride_data[,.N]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Dictionary\n",
    "\n",
    "Each record represents one rider commute opportunty (rider / date / commute).\n",
    "\n",
    "**Note that** there is one record for each commute / data for every rider \n",
    "*After their first ride date*.  This is because the choice to ride (`did_ride`) \n",
    "is conditioned on the rider's history of riding, and which is not available \n",
    "on thier first ride.\n",
    "\n",
    "#### Identifiers\n",
    "* **aid**: Rider number (anonomyzed Numeric)\n",
    "* **fAid**: Rider number (anonomyzed Factor)\n",
    "* **date**: Date of the ride (as Date)\n",
    "* **fDate**: Date of the ride (as Factor)\n",
    "* **AfternoonId**: Function of Date, only true for Route 5\n",
    "\n",
    "#### Main outcome / predictor\n",
    "* **did_ride**: Did the rider ride on this date?\n",
    "* **imputed_new_buses**: The weighted average of the fraction of new busses \n",
    "     on the routes the rider took on the last (up to) 10 trips\n",
    "\n",
    "#### Time since last ride\n",
    "* **commutes_since_last_ride**: Number of commutes since rider's last ride (numeric; range 1 - 461)\n",
    "* **f_commutes_since_last_ride**: Number of commutes since rider's last ride (factor; range \"1\" - \"40+\")\n",
    "     \n",
    "#### Date based indicators\n",
    "* **SR520WBHOV**: SR 520 West Bound is open (Function of the date)\n",
    "* **SR520EBHOV**: SR 520 East Bound is open (Function of the date)\n",
    "* **I405HOV**: Is a 405 HOV is open (Function of the date )\n",
    "* **Route5Expansion**: Route 5 expanded (Function of Date )\n",
    "\n",
    "#### Features based on the rider's history\n",
    "* **route_X_10_ride** (e.g. `route_3_10_ride`):  Fraction of the rider's last 10 rides that were taken on route X\n",
    "* **is_peak_10_ride**: Fraction of the rider's last 10 rides that were taken **during peak traffic**\n",
    "* **IsESOther_10_ride**: Fraction of the rider's last 10 rides that were taken on **EastSide (other) routes**\n",
    "* **IsRouteSeattle_10_ride**: Fraction of the rider's last 10 rides that were taken on **Seattle Routes**\n",
    "* **Is405North_10_ride**: Fraction of the rider's last 10 rides that were taken on **I 405 North Routes**\n",
    "* **IsCoach_10_ride**: Fraction of the rider's last 10 rides that were taken on  **Coach (as opposed to shuttle) busses**\n",
    "* **first_stop_10_ride**: Fraction of the rider's last 10 rides that were taken from **the last AM stop**\n",
    "* **last_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on  **the first AM stop**\n",
    "* **single_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on **a Single Stop Route**\n",
    "* **vehicle_is_new_10_ride**: Fraction of the rider's last 10 rides that were taken on **a new vehicle**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Handy Utility function for fitting models and gathering summary statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' A cute little function for fitting a model and pulling out the headline statistics\n",
    "#'\n",
    "#' @param data A dataset for fitting the model\n",
    "#' @param model A number for identifying the model in a table (these second field in the \"coef\" output)\n",
    "#' @param lhs The left hand side of the model (as a string)\n",
    "#' @param predictors The effects of interested.  Specifically these are the effects that will be pulled out in the summary table\n",
    "#' @param adjust_for The fixed effects that will be included in the right hand side but not pulled out into the summar table\n",
    "#'\n",
    "#' @return A list containing the glm model (`$model`), and a matrix of interesting statistics from the\n",
    "#'       various models (`$coef`)\n",
    "\n",
    "fit_ridership_logit_models <- function(data,\n",
    "                                        model=1,\n",
    "                                        lhs=\"did_ride\",\n",
    "                                        predictors=\"new_fraction_10day\",\n",
    "                                        adjust_for=c(\"fDate\",route_field),# up to 231 levels\n",
    "                                        quick=FALSE,\n",
    "                                        granularity=\"\"){\n",
    "\n",
    "    \n",
    "    # build and test the formula \n",
    "    (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "    .updated = as.character(update(FMLA,~.))\n",
    "    if(length(.updated)>1){\n",
    "        .rhs = .updated[3]\n",
    "    }else{\n",
    "        .rhs = strsplit(as.character(update(FMLA,~.)),\" *~ *\")[[1]][2]\n",
    "    }\n",
    "    .terms = strsplit(.rhs,\" *\\\\+ *\")[[1]]\n",
    "    \n",
    "    \n",
    "    .vars = get.vars(rhs(FMLA))\n",
    "    if(any(! (.vars %in% names(data))))\n",
    "           stop(paste(\"missing variable: \",.vars[! (.vars %in% names(data))],collapse=\"\\\\n\"))\n",
    "           \n",
    "    if(any(!(predictors %in% .terms))){\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        cat(\"terms :\\n\")\n",
    "        cat(paste0(.terms,\"\\n\"))\n",
    "        cat(\"\\npredictors :\\n\")\n",
    "        cat(paste0(predictors[!(predictors %in% .terms)],\"\\n\"))\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        stop(\"Bad Predctors\")\n",
    "        \n",
    "    }    \n",
    "    \n",
    "    quick_N <- 5e5\n",
    "    if(quick & data[,.N] > quick_N)\n",
    "        data <- data[sample(.N,quick_N)]\n",
    "    \n",
    "    # FIT THE OLS MODELS\n",
    "    LM <- glm(FMLA, data = data,family=binomial) # required for the wild bootstrap\n",
    "    \n",
    "    # SUMMARY OF THE OLS MODEL\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "    cat(\"Model \",model,\":\")\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "   \n",
    "    cat(\"\\n\\nCoefficients from Linear model (adjust_for effects omitted):\\n\")\n",
    "    \n",
    "    # catch the re-ordering of interaction terms introduced by the update(form,dev.new ~ .) call in cluster.wild.glm\n",
    "    tryCatch({\n",
    "        print(coef(summary(LM))[c(\"(Intercept)\",predictors),])    \n",
    "    },error = function(err){\n",
    "        model_coef = dimnames(coef(summary(LM)))[[1]]\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "            print(FMLA)\n",
    "            print(coef(summary(LM)))\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "        cat(\"Missing coefficients:\\n\",\n",
    "            predictors[! predictors %in% model_coef])\n",
    "        cat(\"\\n\\nAvailable coefficients:\\n\")\n",
    "        \n",
    "        print(model_coef)\n",
    "        stop(err)\n",
    "    })\n",
    "\n",
    "    # MAKE THE PRETTY OUTPUT\n",
    "    # without doing the (slow) wild bootstrap\n",
    "    out <- cbind(model=model,\n",
    "                rbind(coef(summary(LM))[predictors,]),\n",
    "                N=data[,.N],\n",
    "                granularity=granularity)\n",
    "\n",
    "    rm(LM); gc() # alas...\n",
    "    dimnames(out)[[1]] <- predictors\n",
    "    return(out)\n",
    "\n",
    "} "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for table 2\n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                   Estimate  Std. Error  z value     Pr(>|z|)\n",
      "(Intercept)       0.7540968 0.015716834 47.98019 0.000000e+00\n",
      "imputed_new_buses 0.1401208 0.007982101 17.55438 5.506976e-69\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate Std. Error   z value\n",
      "(Intercept)                              0.74492203 0.01665799 44.718595\n",
      "imputed_new_buses                        0.12527224 0.01198205 10.454993\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.02669334 0.01606475  1.661609\n",
      "                                             Pr(>|z|)\n",
      "(Intercept)                              0.000000e+00\n",
      "imputed_new_buses                        1.390091e-25\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 9.659119e-02\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate Std. Error    z value\n",
      "(Intercept)                               0.88702916 0.02674815 33.1622637\n",
      "imputed_new_buses                         0.17042412 0.01639040 10.3978042\n",
      "imputed_new_buses:IsRouteSeattle_10_ride -0.01780722 0.02349696 -0.7578524\n",
      "                                              Pr(>|z|)\n",
      "(Intercept)                              3.769830e-241\n",
      "imputed_new_buses                         2.537122e-25\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  4.485394e-01\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate Std. Error    z value\n",
      "(Intercept)                               0.88702916 0.02674815 33.1622637\n",
      "imputed_new_buses                         0.17042412 0.01639040 10.3978042\n",
      "imputed_new_buses:IsRouteSeattle_10_ride -0.01780722 0.02349696 -0.7578524\n",
      "                                              Pr(>|z|)\n",
      "(Intercept)                              3.769830e-241\n",
      "imputed_new_buses                         2.537122e-25\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  4.485394e-01\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                   Estimate Std. Error  z value     Pr(>|z|)\n",
      "(Intercept)       0.7044690 0.01659734 42.44468 0.000000e+00\n",
      "imputed_new_buses 0.1532614 0.01062657 14.42247 3.737076e-47\n",
      "\n",
      "===============================================\n",
      "Model  6 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                    Estimate Std. Error    z value     Pr(>|z|)\n",
      "(Intercept)       -0.6342023 3.31105719 -0.1915407 8.481020e-01\n",
      "imputed_new_buses  0.1257439 0.01218812 10.3169233 5.908628e-25\n"
     ]
    }
   ],
   "source": [
    "TABLE_2_MODELS_pre_hov <- list(\n",
    "    \n",
    "        M1 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                                 (!SR520EBHOV)],\n",
    "                                    predictors=c(\"imputed_new_buses\"),\n",
    "                                    adjust_for=c(route_field,\n",
    "                                                 \"f_commutes_since_last_ride\"),\n",
    "                                    model=1,\n",
    "                                    granularity=\"rider/date/commute [Pre-HOV]\"),\n",
    "    \n",
    "        M2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                                 (!SR520EBHOV)],\n",
    "                                    predictors=c(\"imputed_new_buses\",\n",
    "                                                 \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(route_field,\n",
    "                                                 \"f_commutes_since_last_ride\"),\n",
    "                                    model=2,\n",
    "                                    granularity=\"rider/date/commute [Pre-HOV]\"),\n",
    "   \n",
    "        M3 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  \n",
    "                                                                 (!SR520EBHOV) & \n",
    "                                                                 (first_stop_10_ride >= 0.5)],\n",
    "                                    predictors=c(\"imputed_new_buses\",\n",
    "                                                 \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(route_field,\n",
    "                                                 \"f_commutes_since_last_ride\"),\n",
    "                                    model=3,\n",
    "                                    granularity=\"rider/date/commute [Pre-HOV; First stop preferred riders]\"),\n",
    "    \n",
    "        M4 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                                 (!SR520EBHOV) & \n",
    "                                                                 (first_stop_10_ride >= 0.5)],\n",
    "                                    predictors=c(\"imputed_new_buses\",\n",
    "                                                 \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(route_field,\n",
    "                                                 \"f_commutes_since_last_ride\"),\n",
    "                                    model=4,\n",
    "                                    granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"),\n",
    "    \n",
    "        M5 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                                 (!SR520EBHOV) & \n",
    "                                                                 IsRouteSeattle_10_ride >= 0.5],\n",
    "                                    predictors=c(\"imputed_new_buses\"),\n",
    "                                    adjust_for=c(route_field,\n",
    "                                                 \"f_commutes_since_last_ride\"),\n",
    "                                    model=5,\n",
    "                                    granularity=\"rider/date/commute [Pre-HOV; Seattle preferred riders]\"),\n",
    "    \n",
    "        M6 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                                 (!SR520EBHOV) & \n",
    "                                                                 IsRouteSeattle_10_ride <= 0.5],\n",
    "                                    predictors=c(\"imputed_new_buses\"),\n",
    "                                    adjust_for=c(route_field,\n",
    "                                                 \"f_commutes_since_last_ride\"),\n",
    "                                    model=6,\n",
    "                                    granularity=\"rider/date/commute [Pre-HOV; Non-Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                          Estimate Std. Error   z value\n",
      "(Intercept)                              0.7863691 0.01962323 40.073376\n",
      "imputed_new_buses                        0.1267239 0.01350279  9.385020\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.0319511 0.01903662  1.678402\n",
      "                                             Pr(>|z|)\n",
      "(Intercept)                              0.000000e+00\n",
      "imputed_new_buses                        6.290470e-21\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 9.326866e-02\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                       </td><td>0.126723917117179                                       </td><td>0.0135027865369392                                      </td><td>9.38501966023861                                        </td><td>6.29047045457147e-21                                    </td><td>753890                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                       </td><td>0.031951100661575                                       </td><td>0.0190366204879634                                      </td><td>1.67840193493259                                        </td><td>0.0932686601414442                                      </td><td>753890                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                                                            & 0.126723917117179                                            & 0.0135027865369392                                           & 9.38501966023861                                             & 6.29047045457147e-21                                         & 753890                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                            & 0.031951100661575                                            & 0.0190366204879634                                           & 1.67840193493259                                             & 0.0932686601414442                                           & 753890                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                                                        | 0.126723917117179                                        | 0.0135027865369392                                       | 9.38501966023861                                         | 6.29047045457147e-21                                     | 753890                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                        | 0.031951100661575                                        | 0.0190366204879634                                       | 1.67840193493259                                         | 0.0932686601414442                                       | 753890                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate         \n",
       "imputed_new_buses                        4     0.126723917117179\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.031951100661575\n",
       "                                         Std. Error         z value         \n",
       "imputed_new_buses                        0.0135027865369392 9.38501966023861\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0190366204879634 1.67840193493259\n",
       "                                         Pr(>|z|)             N     \n",
       "imputed_new_buses                        6.29047045457147e-21 753890\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0932686601414442   753890\n",
       "                                         granularity                                             \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(T2_M4 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (last_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(route_field,\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 2 Summary Statistics \n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                         </td><td>0.140120801150163                                         </td><td>0.00798210136098698                                       </td><td>17.5543750715835                                          </td><td>5.50697561616006e-69                                      </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                         </td><td>0.125272243758279                                         </td><td>0.0119820495181491                                        </td><td>10.4549929933547                                          </td><td>1.39009053220358e-25                                      </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                                                         </td><td>0.0266933368171675                                        </td><td>0.0160647520569745                                        </td><td>1.66160901347858                                          </td><td>0.0965911949245293                                        </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                         </td><td>0.170424118826176                                         </td><td>0.016390395040229                                         </td><td>10.3978042266756                                          </td><td>2.53712158120574e-25                                      </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                         </td><td>-0.0178072241541702                                       </td><td>0.0234969564377212                                        </td><td>-0.757852371279162                                        </td><td>0.448539366036269                                         </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                         </td><td>0.170424118826176                                         </td><td>0.016390395040229                                         </td><td>10.3978042266756                                          </td><td>2.53712158120574e-25                                      </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                         </td><td>-0.0178072241541702                                       </td><td>0.0234969564377212                                        </td><td>-0.757852371279162                                        </td><td>0.448539366036269                                         </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                         </td><td>0.153261410849855                                         </td><td>0.0106265693267687                                        </td><td>14.4224731554504                                          </td><td>3.73707557603452e-47                                      </td><td>733928                                                    </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]    </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>6                                                         </td><td>0.125743860408519                                         </td><td>0.012188116294084                                         </td><td>10.316923253313                                           </td><td>5.90862824086962e-25                                      </td><td>370670                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                              & 0.140120801150163                                              & 0.00798210136098698                                            & 17.5543750715835                                               & 5.50697561616006e-69                                           & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 2                                                              & 0.125272243758279                                              & 0.0119820495181491                                             & 10.4549929933547                                               & 1.39009053220358e-25                                           & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                                              & 0.0266933368171675                                             & 0.0160647520569745                                             & 1.66160901347858                                               & 0.0965911949245293                                             & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 3                                                              & 0.170424118826176                                              & 0.016390395040229                                              & 10.3978042266756                                               & 2.53712158120574e-25                                           & 471656                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                              & -0.0178072241541702                                            & 0.0234969564377212                                             & -0.757852371279162                                             & 0.448539366036269                                              & 471656                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses & 4                                                              & 0.170424118826176                                              & 0.016390395040229                                              & 10.3978042266756                                               & 2.53712158120574e-25                                           & 471656                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                              & -0.0178072241541702                                            & 0.0234969564377212                                             & -0.757852371279162                                             & 0.448539366036269                                              & 471656                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses & 5                                                              & 0.153261410849855                                              & 0.0106265693267687                                             & 14.4224731554504                                               & 3.73707557603452e-47                                           & 733928                                                         & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}    \\\\\n",
       "\timputed\\_new\\_buses & 6                                                              & 0.125743860408519                                              & 0.012188116294084                                              & 10.316923253313                                                & 5.90862824086962e-25                                           & 370670                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                          | 0.140120801150163                                          | 0.00798210136098698                                        | 17.5543750715835                                           | 5.50697561616006e-69                                       | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 2                                                          | 0.125272243758279                                          | 0.0119820495181491                                         | 10.4549929933547                                           | 1.39009053220358e-25                                       | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                                                          | 0.0266933368171675                                         | 0.0160647520569745                                         | 1.66160901347858                                           | 0.0965911949245293                                         | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 3                                                          | 0.170424118826176                                          | 0.016390395040229                                          | 10.3978042266756                                           | 2.53712158120574e-25                                       | 471656                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                          | -0.0178072241541702                                        | 0.0234969564377212                                         | -0.757852371279162                                         | 0.448539366036269                                          | 471656                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses | 4                                                          | 0.170424118826176                                          | 0.016390395040229                                          | 10.3978042266756                                           | 2.53712158120574e-25                                       | 471656                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                          | -0.0178072241541702                                        | 0.0234969564377212                                         | -0.757852371279162                                         | 0.448539366036269                                          | 471656                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses | 5                                                          | 0.153261410849855                                          | 0.0106265693267687                                         | 14.4224731554504                                           | 3.73707557603452e-47                                       | 733928                                                     | rider/date/commute [Pre-HOV; Seattle preferred riders]     |\n",
       "| imputed_new_buses | 6                                                          | 0.125743860408519                                          | 0.012188116294084                                          | 10.316923253313                                            | 5.90862824086962e-25                                       | 370670                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate           \n",
       "imputed_new_buses                        1     0.140120801150163  \n",
       "imputed_new_buses                        2     0.125272243758279  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.0266933368171675 \n",
       "imputed_new_buses                        3     0.170424118826176  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     -0.0178072241541702\n",
       "imputed_new_buses                        4     0.170424118826176  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     -0.0178072241541702\n",
       "imputed_new_buses                        5     0.153261410849855  \n",
       "imputed_new_buses                        6     0.125743860408519  \n",
       "                                         Std. Error          z value           \n",
       "imputed_new_buses                        0.00798210136098698 17.5543750715835  \n",
       "imputed_new_buses                        0.0119820495181491  10.4549929933547  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0160647520569745  1.66160901347858  \n",
       "imputed_new_buses                        0.016390395040229   10.3978042266756  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0234969564377212  -0.757852371279162\n",
       "imputed_new_buses                        0.016390395040229   10.3978042266756  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0234969564377212  -0.757852371279162\n",
       "imputed_new_buses                        0.0106265693267687  14.4224731554504  \n",
       "imputed_new_buses                        0.012188116294084   10.316923253313   \n",
       "                                         Pr(>|z|)             N      \n",
       "imputed_new_buses                        5.50697561616006e-69 1104348\n",
       "imputed_new_buses                        1.39009053220358e-25 1104348\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0965911949245293   1104348\n",
       "imputed_new_buses                        2.53712158120574e-25 471656 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.448539366036269    471656 \n",
       "imputed_new_buses                        2.53712158120574e-25 471656 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.448539366036269    471656 \n",
       "imputed_new_buses                        3.73707557603452e-47 733928 \n",
       "imputed_new_buses                        5.90862824086962e-25 370670 \n",
       "                                         granularity                                               \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Seattle preferred riders]    \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_2_pre_hov <- do.call(rbind,lapply(TABLE_2_MODELS_pre_hov,function(x)x$coef)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                 Estimate  Std. Error  z value      Pr(>|z|)\n",
      "(Intercept)                     0.7286178 0.033469813 21.76940 4.524938e-105\n",
      "post_hov:IsRouteSeattle_10_ride 0.1282418 0.008522133 15.04809  3.553671e-51\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                   Estimate Std. Error\n",
      "(Intercept)                                      0.57785056 0.03395951\n",
      "post_hov:IsRouteSeattle_10_ride                  0.05000544 0.01872257\n",
      "is_peak_10_ride                                  0.04929952 0.01300476\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride           0.17567419 0.01563867\n",
      "post_hov:is_peak_10_ride                        -0.15153378 0.02179871\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride  0.11414023 0.02638926\n",
      "                                                  z value     Pr(>|z|)\n",
      "(Intercept)                                     17.015870 6.263595e-65\n",
      "post_hov:IsRouteSeattle_10_ride                  2.670864 7.565639e-03\n",
      "is_peak_10_ride                                  3.790882 1.501134e-04\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride          11.233324 2.797532e-29\n",
      "post_hov:is_peak_10_ride                        -6.951501 3.614205e-12\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride  4.325254 1.523565e-05\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                 Estimate Std. Error   z value     Pr(>|z|)\n",
      "(Intercept)                     0.7733802 0.05037790 15.351577 3.456807e-53\n",
      "post_hov:IsRouteSeattle_10_ride 0.1195639 0.01261126  9.480721 2.525333e-21\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                 Estimate Std. Error z value     Pr(>|z|)\n",
      "(Intercept)                     0.7742011 0.04022576 19.2464 1.513095e-82\n",
      "post_hov:IsRouteSeattle_10_ride 0.1309415 0.01004653 13.0335 7.889943e-39\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                  Estimate Std. Error   z value      Pr(>|z|)\n",
      "(Intercept)                     1.12075130 0.05139953 21.804701 2.093693e-105\n",
      "post_hov:IsRouteSeattle_10_ride 0.03597245 0.01406572  2.557455  1.054411e-02\n"
     ]
    }
   ],
   "source": [
    "commute_ride_data[,post_hov :=  0 + ((AfternoonId ==0 & SR520WBHOV) | (AfternoonId ==1 & SR520EBHOV))]\n",
    "\n",
    "TABLE_3_MODELS <- list(\n",
    "    \n",
    "        M1 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                                    predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                                 \"f_commutes_since_last_ride\",\n",
    "                                                 route_field),\n",
    "                                    model=1,\n",
    "                                    granularity=\"rider/date/commute\"),\n",
    "    \n",
    "        M2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                                    predictors=c(\"post_hov:IsRouteSeattle_10_ride\",\n",
    "                                                 \"is_peak_10_ride\",\n",
    "                                                 \"IsRouteSeattle_10_ride:is_peak_10_ride\",\n",
    "                                                 \"post_hov:is_peak_10_ride\",\n",
    "                                                 \"post_hov:IsRouteSeattle_10_ride:is_peak_10_ride\"\n",
    "                                            ),\n",
    "                                    model=2,\n",
    "                                    adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                                 \"f_commutes_since_last_ride\",\n",
    "                                                 route_field),\n",
    "                                    granularity=\"rider/date/commute\"),\n",
    "    \n",
    "        M3 = fit_ridership_logit_models(data = commute_ride_data[first_stop_10_ride >= 0.5],\n",
    "                                    predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(\"imputed_new_buses\",\n",
    "                                                 \"fDate\",\n",
    "                                                 \"f_commutes_since_last_ride\",\n",
    "                                                 route_field),\n",
    "                                    model=3,\n",
    "                                    granularity=\"rider/date/commute [first stop prefered riders]\"),\n",
    "    \n",
    "        M4 = fit_ridership_logit_models(data = commute_ride_data[last_stop_10_ride >= 0.5],\n",
    "                                    predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(\"imputed_new_buses\",\n",
    "                                                 \"fDate\",\n",
    "                                                 \"f_commutes_since_last_ride\",\n",
    "                                                 route_field),\n",
    "                                    model=4,\n",
    "                                    granularity=\"rider/date/commute [last stop prefered riders]\"),\n",
    "    \n",
    "        M5 = fit_ridership_logit_models(data = commute_ride_data[date >= as.Date(\"2016-03-01\") & \n",
    "                                                                  date < as.Date(\"2016-07-01\")],\n",
    "                                    predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                                    adjust_for=c(\"imputed_new_buses\",\n",
    "                                                 \"fDate\",\n",
    "                                                 \"f_commutes_since_last_ride\",\n",
    "                                                 route_field),\n",
    "                                    model=5,\n",
    "                                    granularity=\"ride/date/commute\")\n",
    "                                    )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 3 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>1                                              </td><td>0.128241791035394                              </td><td>0.00852213298216182                            </td><td>15.0480861192643                               </td><td>3.55367147694608e-51                           </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>2                                              </td><td>0.0500054382332144                             </td><td>0.0187225729964354                             </td><td>2.67086357429264                               </td><td>0.00756563889910588                            </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                                              </td><td>0.0492995201063648                             </td><td>0.0130047632871258                             </td><td>3.79088177292465                               </td><td>0.000150113401139927                           </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.17567419297544                               </td><td>0.0156386656073575                             </td><td>11.2333236982055                               </td><td>2.79753165530901e-29                           </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:is_peak_10_ride</th><td>2                                              </td><td>-0.15153377981754                              </td><td>0.0217987145084252                             </td><td>-6.95150072996149                              </td><td>3.61420540829101e-12                           </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.11414022616847                               </td><td>0.0263892569102599                             </td><td>4.32525351345129                               </td><td>1.52356543685152e-05                           </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>3                                              </td><td>0.119563866942413                              </td><td>0.0126112637474343                             </td><td>9.48072051595443                               </td><td>2.5253325888641e-21                            </td><td>762048                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>4                                              </td><td>0.130941459443374                              </td><td>0.0100465277790909                             </td><td>13.0335039451036                               </td><td>7.88994295137041e-39                           </td><td>1218882                                        </td><td>rider/date/commute [last stop prefered riders] </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>5                                              </td><td>0.0359724507758882                             </td><td>0.0140657199357491                             </td><td>2.55745535530404                               </td><td>0.0105441091691188                             </td><td>679992                                         </td><td>ride/date/commute                              </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 1                                               & 0.128241791035394                               & 0.00852213298216182                             & 15.0480861192643                                & 3.55367147694608e-51                            & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 2                                               & 0.0500054382332144                              & 0.0187225729964354                              & 2.67086357429264                                & 0.00756563889910588                             & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                                               & 0.0492995201063648                              & 0.0130047632871258                              & 3.79088177292465                                & 0.000150113401139927                            & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.17567419297544                                & 0.0156386656073575                              & 11.2333236982055                                & 2.79753165530901e-29                            & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:is\\_peak\\_10\\_ride & 2                                               & -0.15153377981754                               & 0.0217987145084252                              & -6.95150072996149                               & 3.61420540829101e-12                            & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.11414022616847                                & 0.0263892569102599                              & 4.32525351345129                                & 1.52356543685152e-05                            & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 3                                                   & 0.119563866942413                                   & 0.0126112637474343                                  & 9.48072051595443                                    & 2.5253325888641e-21                                 & 762048                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 4                                                   & 0.130941459443374                                   & 0.0100465277790909                                  & 13.0335039451036                                    & 7.88994295137041e-39                                & 1218882                                             & rider/date/commute {[}last stop prefered riders{]} \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 5                                               & 0.0359724507758882                              & 0.0140657199357491                              & 2.55745535530404                                & 0.0105441091691188                              & 679992                                          & ride/date/commute                              \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 1                                               | 0.128241791035394                               | 0.00852213298216182                             | 15.0480861192643                                | 3.55367147694608e-51                            | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 2                                               | 0.0500054382332144                              | 0.0187225729964354                              | 2.67086357429264                                | 0.00756563889910588                             | 1792156                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride | 2                                               | 0.0492995201063648                              | 0.0130047632871258                              | 3.79088177292465                                | 0.000150113401139927                            | 1792156                                         | rider/date/commute                              |\n",
       "| IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.17567419297544                                | 0.0156386656073575                              | 11.2333236982055                                | 2.79753165530901e-29                            | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:is_peak_10_ride | 2                                               | -0.15153377981754                               | 0.0217987145084252                              | -6.95150072996149                               | 3.61420540829101e-12                            | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.11414022616847                                | 0.0263892569102599                              | 4.32525351345129                                | 1.52356543685152e-05                            | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 3                                               | 0.119563866942413                               | 0.0126112637474343                              | 9.48072051595443                                | 2.5253325888641e-21                             | 762048                                          | rider/date/commute [first stop prefered riders] |\n",
       "| post_hov:IsRouteSeattle_10_ride | 4                                               | 0.130941459443374                               | 0.0100465277790909                              | 13.0335039451036                                | 7.88994295137041e-39                            | 1218882                                         | rider/date/commute [last stop prefered riders]  |\n",
       "| post_hov:IsRouteSeattle_10_ride | 5                                               | 0.0359724507758882                              | 0.0140657199357491                              | 2.55745535530404                                | 0.0105441091691188                              | 679992                                          | ride/date/commute                               |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model Estimate          \n",
       "post_hov:IsRouteSeattle_10_ride                 1     0.128241791035394 \n",
       "post_hov:IsRouteSeattle_10_ride                 2     0.0500054382332144\n",
       "is_peak_10_ride                                 2     0.0492995201063648\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2     0.17567419297544  \n",
       "post_hov:is_peak_10_ride                        2     -0.15153377981754 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 2     0.11414022616847  \n",
       "post_hov:IsRouteSeattle_10_ride                 3     0.119563866942413 \n",
       "post_hov:IsRouteSeattle_10_ride                 4     0.130941459443374 \n",
       "post_hov:IsRouteSeattle_10_ride                 5     0.0359724507758882\n",
       "                                                Std. Error         \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00852213298216182\n",
       "post_hov:IsRouteSeattle_10_ride                 0.0187225729964354 \n",
       "is_peak_10_ride                                 0.0130047632871258 \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.0156386656073575 \n",
       "post_hov:is_peak_10_ride                        0.0217987145084252 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.0263892569102599 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0126112637474343 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0100465277790909 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0140657199357491 \n",
       "                                                z value          \n",
       "post_hov:IsRouteSeattle_10_ride                 15.0480861192643 \n",
       "post_hov:IsRouteSeattle_10_ride                 2.67086357429264 \n",
       "is_peak_10_ride                                 3.79088177292465 \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          11.2333236982055 \n",
       "post_hov:is_peak_10_ride                        -6.95150072996149\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 4.32525351345129 \n",
       "post_hov:IsRouteSeattle_10_ride                 9.48072051595443 \n",
       "post_hov:IsRouteSeattle_10_ride                 13.0335039451036 \n",
       "post_hov:IsRouteSeattle_10_ride                 2.55745535530404 \n",
       "                                                Pr(>|z|)             N      \n",
       "post_hov:IsRouteSeattle_10_ride                 3.55367147694608e-51 1792156\n",
       "post_hov:IsRouteSeattle_10_ride                 0.00756563889910588  1792156\n",
       "is_peak_10_ride                                 0.000150113401139927 1792156\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2.79753165530901e-29 1792156\n",
       "post_hov:is_peak_10_ride                        3.61420540829101e-12 1792156\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 1.52356543685152e-05 1792156\n",
       "post_hov:IsRouteSeattle_10_ride                 2.5253325888641e-21  762048 \n",
       "post_hov:IsRouteSeattle_10_ride                 7.88994295137041e-39 1218882\n",
       "post_hov:IsRouteSeattle_10_ride                 0.0105441091691188   679992 \n",
       "                                                granularity                                    \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "is_peak_10_ride                                 rider/date/commute                             \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          rider/date/commute                             \n",
       "post_hov:is_peak_10_ride                        rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute [first stop prefered riders]\n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute [last stop prefered riders] \n",
       "post_hov:IsRouteSeattle_10_ride                 ride/date/commute                              "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_3 <- do.call(rbind,lapply(TABLE_3_MODELS,function(x)x$coef)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                    Estimate Std. Error  z value     Pr(>|z|)\n",
      "(Intercept)       -0.7504163 0.53725899 -1.39675 0.1624888865\n",
      "imputed_new_buses  0.1059116 0.03190205  3.31990 0.0009004985\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                </td><td>0.105911611025305                                </td><td>0.0319020530801089                               </td><td>3.31989952995664                                 </td><td>0.000900498496348052                             </td><td>166934                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                     & 0.105911611025305                                     & 0.0319020530801089                                    & 3.31989952995664                                      & 0.000900498496348052                                  & 166934                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                 | 0.105911611025305                                 | 0.0319020530801089                                | 3.31989952995664                                  | 0.000900498496348052                              | 166934                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model Estimate          Std. Error         z value         \n",
       "imputed_new_buses 1     0.105911611025305 0.0319020530801089 3.31989952995664\n",
       "                  Pr(>|z|)             N     \n",
       "imputed_new_buses 0.000900498496348052 166934\n",
       "                  granularity                                      \n",
       "imputed_new_buses rider/date/commute [Single Stop Preferred Riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M1 = fit_ridership_logit_models(data = commute_ride_data[(single_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            route_field),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Single Stop Preferred Riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                         Estimate Std. Error   z value\n",
      "(Intercept)                            0.69260146 0.03342644 20.720169\n",
      "imputed_new_buses                     -0.08793786 0.01043766 -8.425055\n",
      "imputed_new_buses:single_stop_10_ride -0.09265170 0.02233106 -4.149005\n",
      "                                          Pr(>|z|)\n",
      "(Intercept)                           2.278837e-95\n",
      "imputed_new_buses                     3.605802e-17\n",
      "imputed_new_buses:single_stop_10_ride 3.339230e-05\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                   </td><td>-0.0879378589130688 </td><td>0.0104376596473189  </td><td>-8.42505522161351   </td><td>3.60580150079163e-17</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                   </td><td>-0.0926516978757409 </td><td>0.0223310623618344  </td><td>-4.14900537979286   </td><td>3.33922964451776e-05</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                    & -0.0879378589130688  & 0.0104376596473189   & -8.42505522161351    & 3.60580150079163e-17 & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                    & -0.0926516978757409  & 0.0223310623618344   & -4.14900537979286    & 3.33922964451776e-05 & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                    | -0.0879378589130688  | 0.0104376596473189   | -8.42505522161351    | 3.60580150079163e-17 | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                    | -0.0926516978757409  | 0.0223310623618344   | -4.14900537979286    | 3.33922964451776e-05 | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                      model Estimate           \n",
       "imputed_new_buses                     2     -0.0879378589130688\n",
       "imputed_new_buses:single_stop_10_ride 2     -0.0926516978757409\n",
       "                                      Std. Error         z value          \n",
       "imputed_new_buses                     0.0104376596473189 -8.42505522161351\n",
       "imputed_new_buses:single_stop_10_ride 0.0223310623618344 -4.14900537979286\n",
       "                                      Pr(>|z|)             N      \n",
       "imputed_new_buses                     3.60580150079163e-17 1792156\n",
       "imputed_new_buses:single_stop_10_ride 3.33922964451776e-05 1792156\n",
       "                                      granularity       \n",
       "imputed_new_buses                     rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:single_stop_10_ride\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            route_field),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                Estimate Std. Error    z value\n",
      "(Intercept)                                   0.66205805 0.03357659 19.7178472\n",
      "imputed_new_buses                            -0.03606079 0.01162612 -3.1017053\n",
      "Is405North_10_ride:I405HOV                    0.16178599 0.16852109  0.9600341\n",
      "imputed_new_buses:I405HOV                    -0.04888831 0.01050903 -4.6520273\n",
      "imputed_new_buses:Is405North_10_ride         -0.11584522 0.01768578 -6.5501894\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.29420879 0.17275156 -1.7030746\n",
      "                                                 Pr(>|z|)\n",
      "(Intercept)                                  1.515427e-86\n",
      "imputed_new_buses                            1.924094e-03\n",
      "Is405North_10_ride:I405HOV                   3.370380e-01\n",
      "imputed_new_buses:I405HOV                    3.286876e-06\n",
      "imputed_new_buses:Is405North_10_ride         5.746416e-11\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV 8.855411e-02\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                   </td><td>-0.0360607882928105 </td><td>0.0116261168704983  </td><td>-3.10170529803601   </td><td>0.00192409402988723 </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                   </td><td>0.161785994403343   </td><td>0.168521087001944   </td><td>0.960034125589735   </td><td>0.337038040191921   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                   </td><td>-0.0488883147296567 </td><td>0.0105090344082788  </td><td>-4.65202727770529   </td><td>3.28687586995428e-06</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                   </td><td>-0.115845215018955  </td><td>0.017685780979405   </td><td>-6.55018939530325   </td><td>5.74641578055859e-11</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                   </td><td>-0.294208786088764  </td><td>0.172751557781111   </td><td>-1.70307457638992   </td><td>0.0885541130305662  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                    & -0.0360607882928105  & 0.0116261168704983   & -3.10170529803601    & 0.00192409402988723  & 1792156              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                    & 0.161785994403343    & 0.168521087001944    & 0.960034125589735    & 0.337038040191921    & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                    & -0.0488883147296567  & 0.0105090344082788   & -4.65202727770529    & 3.28687586995428e-06 & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                    & -0.115845215018955   & 0.017685780979405    & -6.55018939530325    & 5.74641578055859e-11 & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                    & -0.294208786088764   & 0.172751557781111    & -1.70307457638992    & 0.0885541130305662   & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                    | -0.0360607882928105  | 0.0116261168704983   | -3.10170529803601    | 0.00192409402988723  | 1792156              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 3                    | 0.161785994403343    | 0.168521087001944    | 0.960034125589735    | 0.337038040191921    | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:I405HOV | 3                    | -0.0488883147296567  | 0.0105090344082788   | -4.65202727770529    | 3.28687586995428e-06 | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                    | -0.115845215018955   | 0.017685780979405    | -6.55018939530325    | 5.74641578055859e-11 | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                    | -0.294208786088764   | 0.172751557781111    | -1.70307457638992    | 0.0885541130305662   | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                             model Estimate           \n",
       "imputed_new_buses                            3     -0.0360607882928105\n",
       "Is405North_10_ride:I405HOV                   3     0.161785994403343  \n",
       "imputed_new_buses:I405HOV                    3     -0.0488883147296567\n",
       "imputed_new_buses:Is405North_10_ride         3     -0.115845215018955 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 3     -0.294208786088764 \n",
       "                                             Std. Error        \n",
       "imputed_new_buses                            0.0116261168704983\n",
       "Is405North_10_ride:I405HOV                   0.168521087001944 \n",
       "imputed_new_buses:I405HOV                    0.0105090344082788\n",
       "imputed_new_buses:Is405North_10_ride         0.017685780979405 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.172751557781111 \n",
       "                                             z value          \n",
       "imputed_new_buses                            -3.10170529803601\n",
       "Is405North_10_ride:I405HOV                   0.960034125589735\n",
       "imputed_new_buses:I405HOV                    -4.65202727770529\n",
       "imputed_new_buses:Is405North_10_ride         -6.55018939530325\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV -1.70307457638992\n",
       "                                             Pr(>|z|)             N      \n",
       "imputed_new_buses                            0.00192409402988723  1792156\n",
       "Is405North_10_ride:I405HOV                   0.337038040191921    1792156\n",
       "imputed_new_buses:I405HOV                    3.28687586995428e-06 1792156\n",
       "imputed_new_buses:Is405North_10_ride         5.74641578055859e-11 1792156\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.0885541130305662   1792156\n",
       "                                             granularity       \n",
       "imputed_new_buses                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:I405HOV                    rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride         rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M3 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            route_field),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                  Estimate Std. Error   z value\n",
      "(Intercept)                                     0.67745211 0.03345830 20.247653\n",
      "imputed_new_buses                              -0.07042626 0.01060075 -6.643517\n",
      "imputed_new_buses:single_stop_10_ride          -0.07071427 0.02436114 -2.902749\n",
      "Is405North_10_ride:I405HOV                      0.23539123 0.16848749  1.397084\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -0.41287466 0.17206302 -2.399555\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -0.05424929 0.04147818 -1.307899\n",
      "                                                   Pr(>|z|)\n",
      "(Intercept)                                    3.725727e-91\n",
      "imputed_new_buses                              3.062842e-11\n",
      "imputed_new_buses:single_stop_10_ride          3.699028e-03\n",
      "Is405North_10_ride:I405HOV                     1.623882e-01\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   1.641502e-02\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV 1.909074e-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                   </td><td>-0.070426263559249  </td><td>0.0106007493813243  </td><td>-6.64351745578679   </td><td>3.06284186657698e-11</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                   </td><td>-0.0707142698843206 </td><td>0.0243611372463758  </td><td>-2.9027491273972    </td><td>0.0036990282194584  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                   </td><td>0.235391234117809   </td><td>0.168487494532588   </td><td>1.39708430451069    </td><td>0.162388221071399   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.412874655665146  </td><td>0.172063017422566   </td><td>-2.3995548947696    </td><td>0.0164150183457182  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.0542492894338359 </td><td>0.0414781797451659  </td><td>-1.30789947309967   </td><td>0.19090740827514    </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                    & -0.070426263559249   & 0.0106007493813243   & -6.64351745578679    & 3.06284186657698e-11 & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                    & -0.0707142698843206  & 0.0243611372463758   & -2.9027491273972     & 0.0036990282194584   & 1792156              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                    & 0.235391234117809    & 0.168487494532588    & 1.39708430451069     & 0.162388221071399    & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                    & -0.412874655665146   & 0.172063017422566    & -2.3995548947696     & 0.0164150183457182   & 1792156              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                    & -0.0542492894338359  & 0.0414781797451659   & -1.30789947309967    & 0.19090740827514     & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                    | -0.070426263559249   | 0.0106007493813243   | -6.64351745578679    | 3.06284186657698e-11 | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                    | -0.0707142698843206  | 0.0243611372463758   | -2.9027491273972     | 0.0036990282194584   | 1792156              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 4                    | 0.235391234117809    | 0.168487494532588    | 1.39708430451069     | 0.162388221071399    | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                    | -0.412874655665146   | 0.172063017422566    | -2.3995548947696     | 0.0164150183457182   | 1792156              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                    | -0.0542492894338359  | 0.0414781797451659   | -1.30789947309967    | 0.19090740827514     | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                               model Estimate           \n",
       "imputed_new_buses                              4     -0.070426263559249 \n",
       "imputed_new_buses:single_stop_10_ride          4     -0.0707142698843206\n",
       "Is405North_10_ride:I405HOV                     4     0.235391234117809  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   4     -0.412874655665146 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 4     -0.0542492894338359\n",
       "                                               Std. Error        \n",
       "imputed_new_buses                              0.0106007493813243\n",
       "imputed_new_buses:single_stop_10_ride          0.0243611372463758\n",
       "Is405North_10_ride:I405HOV                     0.168487494532588 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.172063017422566 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.0414781797451659\n",
       "                                               z value          \n",
       "imputed_new_buses                              -6.64351745578679\n",
       "imputed_new_buses:single_stop_10_ride          -2.9027491273972 \n",
       "Is405North_10_ride:I405HOV                     1.39708430451069 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -2.3995548947696 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV -1.30789947309967\n",
       "                                               Pr(>|z|)             N      \n",
       "imputed_new_buses                              3.06284186657698e-11 1792156\n",
       "imputed_new_buses:single_stop_10_ride          0.0036990282194584   1792156\n",
       "Is405North_10_ride:I405HOV                     0.162388221071399    1792156\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.0164150183457182   1792156\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.19090740827514     1792156\n",
       "                                               granularity       \n",
       "imputed_new_buses                              rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride          rider/date/commute\n",
       "Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M4 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            route_field),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                                    Estimate\n",
      "(Intercept)                                                       0.67783047\n",
      "imputed_new_buses                                                -0.07107844\n",
      "imputed_new_buses:single_stop_10_ride                            -0.06608321\n",
      "Is405North_10_ride:I405HOV                                       -0.47246628\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                      0.31273078\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    3.74495836\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -3.89330836\n",
      "                                                                 Std. Error\n",
      "(Intercept)                                                      0.03345866\n",
      "imputed_new_buses                                                0.01060153\n",
      "imputed_new_buses:single_stop_10_ride                            0.02437423\n",
      "Is405North_10_ride:I405HOV                                       0.21074172\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     0.21547129\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.66973383\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.68522664\n",
      "                                                                   z value\n",
      "(Intercept)                                                      20.258747\n",
      "imputed_new_buses                                                -6.704545\n",
      "imputed_new_buses:single_stop_10_ride                            -2.711192\n",
      "Is405North_10_ride:I405HOV                                       -2.241921\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                      1.451380\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    5.591711\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -5.681782\n",
      "                                                                     Pr(>|z|)\n",
      "(Intercept)                                                      2.974370e-91\n",
      "imputed_new_buses                                                2.020352e-11\n",
      "imputed_new_buses:single_stop_10_ride                            6.704185e-03\n",
      "Is405North_10_ride:I405HOV                                       2.496648e-02\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     1.466740e-01\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   2.248422e-08\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1.332985e-08\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                   </td><td>-0.0710784419246492 </td><td>0.0106015313403451  </td><td>-6.70454480987605   </td><td>2.02035152132031e-11</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                   </td><td>-0.0660832083449725 </td><td>0.0243742293718409  </td><td>-2.71119169910321   </td><td>0.00670418541728965 </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.472466283046493  </td><td>0.210741718157162   </td><td>-2.24192099778814   </td><td>0.0249664786873672  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.312730775848575   </td><td>0.215471290232862   </td><td>1.45138025353913    </td><td>0.146674005181171   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>3.74495836186715    </td><td>0.66973383216529    </td><td>5.59171148597864    </td><td>2.24842210103525e-08</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-3.89330835753941   </td><td>0.685226637417744   </td><td>-5.68178197539317   </td><td>1.33298520405553e-08</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                    & -0.0710784419246492  & 0.0106015313403451   & -6.70454480987605    & 2.02035152132031e-11 & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                    & -0.0660832083449725  & 0.0243742293718409   & -2.71119169910321    & 0.00670418541728965  & 1792156              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                    & -0.472466283046493   & 0.210741718157162    & -2.24192099778814    & 0.0249664786873672   & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                    & 0.312730775848575    & 0.215471290232862    & 1.45138025353913     & 0.146674005181171    & 1792156              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & 3.74495836186715     & 0.66973383216529     & 5.59171148597864     & 2.24842210103525e-08 & 1792156              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & -3.89330835753941    & 0.685226637417744    & -5.68178197539317    & 1.33298520405553e-08 & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                    | -0.0710784419246492  | 0.0106015313403451   | -6.70454480987605    | 2.02035152132031e-11 | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                    | -0.0660832083449725  | 0.0243742293718409   | -2.71119169910321    | 0.00670418541728965  | 1792156              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 5                    | -0.472466283046493   | 0.210741718157162    | -2.24192099778814    | 0.0249664786873672   | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                    | 0.312730775848575    | 0.215471290232862    | 1.45138025353913     | 0.146674005181171    | 1792156              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | 3.74495836186715     | 0.66973383216529     | 5.59171148597864     | 2.24842210103525e-08 | 1792156              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | -3.89330835753941    | 0.685226637417744    | -5.68178197539317    | 1.33298520405553e-08 | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate           \n",
       "imputed_new_buses                                                -0.0710784419246492\n",
       "imputed_new_buses:single_stop_10_ride                            -0.0660832083449725\n",
       "Is405North_10_ride:I405HOV                                       -0.472466283046493 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.312730775848575  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.74495836186715   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -3.89330835753941  \n",
       "                                                                 Std. Error        \n",
       "imputed_new_buses                                                0.0106015313403451\n",
       "imputed_new_buses:single_stop_10_ride                            0.0243742293718409\n",
       "Is405North_10_ride:I405HOV                                       0.210741718157162 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.215471290232862 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.66973383216529  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.685226637417744 \n",
       "                                                                 z value          \n",
       "imputed_new_buses                                                -6.70454480987605\n",
       "imputed_new_buses:single_stop_10_ride                            -2.71119169910321\n",
       "Is405North_10_ride:I405HOV                                       -2.24192099778814\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1.45138025353913 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5.59171148597864 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -5.68178197539317\n",
       "                                                                 Pr(>|z|)            \n",
       "imputed_new_buses                                                2.02035152132031e-11\n",
       "imputed_new_buses:single_stop_10_ride                            0.00670418541728965 \n",
       "Is405North_10_ride:I405HOV                                       0.0249664786873672  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.146674005181171   \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   2.24842210103525e-08\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1.33298520405553e-08\n",
       "                                                                 N      \n",
       "imputed_new_buses                                                1792156\n",
       "imputed_new_buses:single_stop_10_ride                            1792156\n",
       "Is405North_10_ride:I405HOV                                       1792156\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1792156\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1792156\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1792156\n",
       "                                                                 granularity       \n",
       "imputed_new_buses                                                rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M5 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            route_field),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 4 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>z value</th><th scope=col>Pr(&gt;|z|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                </td><td>0.105911611025305                                </td><td>0.0319020530801089                               </td><td>3.31989952995664                                 </td><td>0.000900498496348052                             </td><td>166934                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                </td><td>-0.0879378589130688                              </td><td>0.0104376596473189                               </td><td>-8.42505522161351                                </td><td>3.60580150079163e-17                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                                                </td><td>-0.0926516978757409                              </td><td>0.0223310623618344                               </td><td>-4.14900537979286                                </td><td>3.33922964451776e-05                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                </td><td>-0.0360607882928105                              </td><td>0.0116261168704983                               </td><td>-3.10170529803601                                </td><td>0.00192409402988723                              </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                                                </td><td>0.161785994403343                                </td><td>0.168521087001944                                </td><td>0.960034125589735                                </td><td>0.337038040191921                                </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                                                </td><td>-0.0488883147296567                              </td><td>0.0105090344082788                               </td><td>-4.65202727770529                                </td><td>3.28687586995428e-06                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                                                </td><td>-0.115845215018955                               </td><td>0.017685780979405                                </td><td>-6.55018939530325                                </td><td>5.74641578055859e-11                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                                                </td><td>-0.294208786088764                               </td><td>0.172751557781111                                </td><td>-1.70307457638992                                </td><td>0.0885541130305662                               </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                </td><td>-0.070426263559249                               </td><td>0.0106007493813243                               </td><td>-6.64351745578679                                </td><td>3.06284186657698e-11                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                                                </td><td>-0.0707142698843206                              </td><td>0.0243611372463758                               </td><td>-2.9027491273972                                 </td><td>0.0036990282194584                               </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.235391234117809                                </td><td>0.168487494532588                                </td><td>1.39708430451069                                 </td><td>0.162388221071399                                </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.412874655665146                               </td><td>0.172063017422566                                </td><td>-2.3995548947696                                 </td><td>0.0164150183457182                               </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.0542492894338359                              </td><td>0.0414781797451659                               </td><td>-1.30789947309967                                </td><td>0.19090740827514                                 </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                </td><td>-0.0710784419246492                              </td><td>0.0106015313403451                               </td><td>-6.70454480987605                                </td><td>2.02035152132031e-11                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                                                </td><td>-0.0660832083449725                              </td><td>0.0243742293718409                               </td><td>-2.71119169910321                                </td><td>0.00670418541728965                              </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.472466283046493                               </td><td>0.210741718157162                                </td><td>-2.24192099778814                                </td><td>0.0249664786873672                               </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.312730775848575                                </td><td>0.215471290232862                                </td><td>1.45138025353913                                 </td><td>0.146674005181171                                </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>3.74495836186715                                 </td><td>0.66973383216529                                 </td><td>5.59171148597864                                 </td><td>2.24842210103525e-08                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-3.89330835753941                                </td><td>0.685226637417744                                </td><td>-5.68178197539317                                </td><td>1.33298520405553e-08                             </td><td>1792156                                          </td><td>rider/date/commute                               </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & z value & Pr(>\\textbar{}z\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                     & 0.105911611025305                                     & 0.0319020530801089                                    & 3.31989952995664                                      & 0.000900498496348052                                  & 166934                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\timputed\\_new\\_buses & 2                                                 & -0.0879378589130688                               & 0.0104376596473189                                & -8.42505522161351                                 & 3.60580150079163e-17                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                                                 & -0.0926516978757409                               & 0.0223310623618344                                & -4.14900537979286                                 & 3.33922964451776e-05                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 3                                                 & -0.0360607882928105                               & 0.0116261168704983                                & -3.10170529803601                                 & 0.00192409402988723                               & 1792156                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                                                 & 0.161785994403343                                 & 0.168521087001944                                 & 0.960034125589735                                 & 0.337038040191921                                 & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                                                 & -0.0488883147296567                               & 0.0105090344082788                                & -4.65202727770529                                 & 3.28687586995428e-06                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                                                 & -0.115845215018955                                & 0.017685780979405                                 & -6.55018939530325                                 & 5.74641578055859e-11                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                                                 & -0.294208786088764                                & 0.172751557781111                                 & -1.70307457638992                                 & 0.0885541130305662                                & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 4                                                 & -0.070426263559249                                & 0.0106007493813243                                & -6.64351745578679                                 & 3.06284186657698e-11                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                                                 & -0.0707142698843206                               & 0.0243611372463758                                & -2.9027491273972                                  & 0.0036990282194584                                & 1792156                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                                                 & 0.235391234117809                                 & 0.168487494532588                                 & 1.39708430451069                                  & 0.162388221071399                                 & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.412874655665146                                & 0.172063017422566                                 & -2.3995548947696                                  & 0.0164150183457182                                & 1792156                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.0542492894338359                               & 0.0414781797451659                                & -1.30789947309967                                 & 0.19090740827514                                  & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 5                                                 & -0.0710784419246492                               & 0.0106015313403451                                & -6.70454480987605                                 & 2.02035152132031e-11                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                                                 & -0.0660832083449725                               & 0.0243742293718409                                & -2.71119169910321                                 & 0.00670418541728965                               & 1792156                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                                                 & -0.472466283046493                                & 0.210741718157162                                 & -2.24192099778814                                 & 0.0249664786873672                                & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.312730775848575                                 & 0.215471290232862                                 & 1.45138025353913                                  & 0.146674005181171                                 & 1792156                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & 3.74495836186715                                  & 0.66973383216529                                  & 5.59171148597864                                  & 2.24842210103525e-08                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & -3.89330835753941                                 & 0.685226637417744                                 & -5.68178197539317                                 & 1.33298520405553e-08                              & 1792156                                           & rider/date/commute                               \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | z value | Pr(>|z|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                 | 0.105911611025305                                 | 0.0319020530801089                                | 3.31989952995664                                  | 0.000900498496348052                              | 166934                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "| imputed_new_buses | 2                                                 | -0.0879378589130688                               | 0.0104376596473189                                | -8.42505522161351                                 | 3.60580150079163e-17                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                                                 | -0.0926516978757409                               | 0.0223310623618344                                | -4.14900537979286                                 | 3.33922964451776e-05                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 3                                                 | -0.0360607882928105                               | 0.0116261168704983                                | -3.10170529803601                                 | 0.00192409402988723                               | 1792156                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 3                                                 | 0.161785994403343                                 | 0.168521087001944                                 | 0.960034125589735                                 | 0.337038040191921                                 | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:I405HOV | 3                                                 | -0.0488883147296567                               | 0.0105090344082788                                | -4.65202727770529                                 | 3.28687586995428e-06                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                                                 | -0.115845215018955                                | 0.017685780979405                                 | -6.55018939530325                                 | 5.74641578055859e-11                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                                                 | -0.294208786088764                                | 0.172751557781111                                 | -1.70307457638992                                 | 0.0885541130305662                                | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 4                                                 | -0.070426263559249                                | 0.0106007493813243                                | -6.64351745578679                                 | 3.06284186657698e-11                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                                                 | -0.0707142698843206                               | 0.0243611372463758                                | -2.9027491273972                                  | 0.0036990282194584                                | 1792156                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 4                                                 | 0.235391234117809                                 | 0.168487494532588                                 | 1.39708430451069                                  | 0.162388221071399                                 | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                                                 | -0.412874655665146                                | 0.172063017422566                                 | -2.3995548947696                                  | 0.0164150183457182                                | 1792156                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                                                 | -0.0542492894338359                               | 0.0414781797451659                                | -1.30789947309967                                 | 0.19090740827514                                  | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 5                                                 | -0.0710784419246492                               | 0.0106015313403451                                | -6.70454480987605                                 | 2.02035152132031e-11                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                                                 | -0.0660832083449725                               | 0.0243742293718409                                | -2.71119169910321                                 | 0.00670418541728965                               | 1792156                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 5                                                 | -0.472466283046493                                | 0.210741718157162                                 | -2.24192099778814                                 | 0.0249664786873672                                | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                                                 | 0.312730775848575                                 | 0.215471290232862                                 | 1.45138025353913                                  | 0.146674005181171                                 | 1792156                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | 3.74495836186715                                  | 0.66973383216529                                  | 5.59171148597864                                  | 2.24842210103525e-08                              | 1792156                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | -3.89330835753941                                 | 0.685226637417744                                 | -5.68178197539317                                 | 1.33298520405553e-08                              | 1792156                                           | rider/date/commute                                |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                1    \n",
       "imputed_new_buses                                                2    \n",
       "imputed_new_buses:single_stop_10_ride                            2    \n",
       "imputed_new_buses                                                3    \n",
       "Is405North_10_ride:I405HOV                                       3    \n",
       "imputed_new_buses:I405HOV                                        3    \n",
       "imputed_new_buses:Is405North_10_ride                             3    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     3    \n",
       "imputed_new_buses                                                4    \n",
       "imputed_new_buses:single_stop_10_ride                            4    \n",
       "Is405North_10_ride:I405HOV                                       4    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     4    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4    \n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate           \n",
       "imputed_new_buses                                                0.105911611025305  \n",
       "imputed_new_buses                                                -0.0879378589130688\n",
       "imputed_new_buses:single_stop_10_ride                            -0.0926516978757409\n",
       "imputed_new_buses                                                -0.0360607882928105\n",
       "Is405North_10_ride:I405HOV                                       0.161785994403343  \n",
       "imputed_new_buses:I405HOV                                        -0.0488883147296567\n",
       "imputed_new_buses:Is405North_10_ride                             -0.115845215018955 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.294208786088764 \n",
       "imputed_new_buses                                                -0.070426263559249 \n",
       "imputed_new_buses:single_stop_10_ride                            -0.0707142698843206\n",
       "Is405North_10_ride:I405HOV                                       0.235391234117809  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.412874655665146 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.0542492894338359\n",
       "imputed_new_buses                                                -0.0710784419246492\n",
       "imputed_new_buses:single_stop_10_ride                            -0.0660832083449725\n",
       "Is405North_10_ride:I405HOV                                       -0.472466283046493 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.312730775848575  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.74495836186715   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -3.89330835753941  \n",
       "                                                                 Std. Error        \n",
       "imputed_new_buses                                                0.0319020530801089\n",
       "imputed_new_buses                                                0.0104376596473189\n",
       "imputed_new_buses:single_stop_10_ride                            0.0223310623618344\n",
       "imputed_new_buses                                                0.0116261168704983\n",
       "Is405North_10_ride:I405HOV                                       0.168521087001944 \n",
       "imputed_new_buses:I405HOV                                        0.0105090344082788\n",
       "imputed_new_buses:Is405North_10_ride                             0.017685780979405 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.172751557781111 \n",
       "imputed_new_buses                                                0.0106007493813243\n",
       "imputed_new_buses:single_stop_10_ride                            0.0243611372463758\n",
       "Is405North_10_ride:I405HOV                                       0.168487494532588 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.172063017422566 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0414781797451659\n",
       "imputed_new_buses                                                0.0106015313403451\n",
       "imputed_new_buses:single_stop_10_ride                            0.0243742293718409\n",
       "Is405North_10_ride:I405HOV                                       0.210741718157162 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.215471290232862 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.66973383216529  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.685226637417744 \n",
       "                                                                 z value          \n",
       "imputed_new_buses                                                3.31989952995664 \n",
       "imputed_new_buses                                                -8.42505522161351\n",
       "imputed_new_buses:single_stop_10_ride                            -4.14900537979286\n",
       "imputed_new_buses                                                -3.10170529803601\n",
       "Is405North_10_ride:I405HOV                                       0.960034125589735\n",
       "imputed_new_buses:I405HOV                                        -4.65202727770529\n",
       "imputed_new_buses:Is405North_10_ride                             -6.55018939530325\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -1.70307457638992\n",
       "imputed_new_buses                                                -6.64351745578679\n",
       "imputed_new_buses:single_stop_10_ride                            -2.9027491273972 \n",
       "Is405North_10_ride:I405HOV                                       1.39708430451069 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -2.3995548947696 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -1.30789947309967\n",
       "imputed_new_buses                                                -6.70454480987605\n",
       "imputed_new_buses:single_stop_10_ride                            -2.71119169910321\n",
       "Is405North_10_ride:I405HOV                                       -2.24192099778814\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1.45138025353913 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5.59171148597864 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -5.68178197539317\n",
       "                                                                 Pr(>|z|)            \n",
       "imputed_new_buses                                                0.000900498496348052\n",
       "imputed_new_buses                                                3.60580150079163e-17\n",
       "imputed_new_buses:single_stop_10_ride                            3.33922964451776e-05\n",
       "imputed_new_buses                                                0.00192409402988723 \n",
       "Is405North_10_ride:I405HOV                                       0.337038040191921   \n",
       "imputed_new_buses:I405HOV                                        3.28687586995428e-06\n",
       "imputed_new_buses:Is405North_10_ride                             5.74641578055859e-11\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0885541130305662  \n",
       "imputed_new_buses                                                3.06284186657698e-11\n",
       "imputed_new_buses:single_stop_10_ride                            0.0036990282194584  \n",
       "Is405North_10_ride:I405HOV                                       0.162388221071399   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0164150183457182  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.19090740827514    \n",
       "imputed_new_buses                                                2.02035152132031e-11\n",
       "imputed_new_buses:single_stop_10_ride                            0.00670418541728965 \n",
       "Is405North_10_ride:I405HOV                                       0.0249664786873672  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.146674005181171   \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   2.24842210103525e-08\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1.33298520405553e-08\n",
       "                                                                 N      \n",
       "imputed_new_buses                                                166934 \n",
       "imputed_new_buses                                                1792156\n",
       "imputed_new_buses:single_stop_10_ride                            1792156\n",
       "imputed_new_buses                                                1792156\n",
       "Is405North_10_ride:I405HOV                                       1792156\n",
       "imputed_new_buses:I405HOV                                        1792156\n",
       "imputed_new_buses:Is405North_10_ride                             1792156\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1792156\n",
       "imputed_new_buses                                                1792156\n",
       "imputed_new_buses:single_stop_10_ride                            1792156\n",
       "Is405North_10_ride:I405HOV                                       1792156\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1792156\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1792156\n",
       "imputed_new_buses                                                1792156\n",
       "imputed_new_buses:single_stop_10_ride                            1792156\n",
       "Is405North_10_ride:I405HOV                                       1792156\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1792156\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1792156\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1792156\n",
       "                                                                 granularity                                      \n",
       "imputed_new_buses                                                rider/date/commute [Single Stop Preferred Riders]\n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:I405HOV                                        rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride                             rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute                               "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_4 <- rbind(T4_M1,T4_M2,T4_M3,T4_M4,T4_M5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
